package nl.vu.few.ibivu.biomodels.client.ui;

import com.google.gwt.json.client.JSONString;

import nl.vu.few.ibivu.biomodels.client.ui.cytoscapeweb.CytoscapeWeb;
import nl.vu.few.ibivu.biomodels.client.ui.cytoscapeweb.CytoscapeWebNode;
import nl.vu.few.ibivu.biomodels.client.ui.view.ComponentDetailsView.Presenter;
import nl.vu.few.ibivu.biomodels.shared.PetrifierDataFieldName;

public class ComponentDetailsEditor implements Presenter {

	CytoscapeWebNode node;
	CytoscapeWeb cytoscapeWeb;
	String name;
	String uniprotId;
	
	public ComponentDetailsEditor(CytoscapeWeb cytoscapeWeb, CytoscapeWebNode node) {
		this.cytoscapeWeb = cytoscapeWeb;
		this.node = node;
		this.name = null;
		this.uniprotId = null;
	}
	
	@Override
	public void save() {
		if (uniprotId != null && !uniprotId.isEmpty()) {
			node.getData().put(PetrifierDataFieldName.UNIPROT_ID.name(), new JSONString(uniprotId));
		}
		else {
			node.getData().put(PetrifierDataFieldName.UNIPROT_ID.name(), null);
		}
		node.getData().setLabel(name);
		cytoscapeWeb.updateNodeData(node);
	}
	
	@Override
	public String getName() {
		return node.getData().getLabel();
	}

	@Override
	public String getUniprotId() {
		return node.getData().get(PetrifierDataFieldName.UNIPROT_ID.name()).toString();
	}

	@Override
	public void setName(String name) {
		this.name = name;
	}

	@Override
	public void setUniprotId(String uniprotId) {
		this.uniprotId = uniprotId;
	}

}
